package com.tansun.easycare.rule.ruleflow.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.tansun.easycare.rule.common.ReferenceModel;
import com.tansun.easycare.rule.common.service.impl.RuleBaseServiceImpl;
import com.tansun.easycare.rule.ruleflow.dao.RuleFlowRectsDao;
import com.tansun.easycare.rule.ruleflow.entity.RuleFlowRects;
import com.tansun.easycare.rule.ruleflow.service.RuleFlowRectsService;

/**
 * 规则流节点ServiceImpl
 *
 * @author lph
 * @version 2017-04-17
 */
@Service("ruleFlowRectsService")
@Transactional(readOnly = true)
public class RuleFlowRectsServiceImpl extends RuleBaseServiceImpl<RuleFlowRectsDao, RuleFlowRects> implements RuleFlowRectsService {

    public RuleFlowRects get(String id) {
        return super.get(id);
    }

    public List<RuleFlowRects> findList(RuleFlowRects ruleFlowRects) {
        return super.findList(ruleFlowRects);
    }

    public PageInfo<RuleFlowRects> findPage(Page<RuleFlowRects> page, RuleFlowRects ruleFlowRects) {
        return super.findPage(page, ruleFlowRects);
    }

    @Transactional(readOnly = false)
    public void save(RuleFlowRects ruleFlowRects) {
        super.save(ruleFlowRects);
    }

    @Transactional(readOnly = false)
    public void delete(RuleFlowRects ruleFlowRects) {
        super.delete(ruleFlowRects);
    }

    public List<ReferenceModel> findListByModelCode(String modelCode,String projectCode) {
        RuleFlowRects condition = new RuleFlowRects();
        condition.setRectCode(modelCode);
        List<RuleFlowRects> rectsList = this.dao.findReferenceRects(condition);
        List<ReferenceModel> referenceList = new ArrayList<ReferenceModel>();
        for (RuleFlowRects rect : rectsList) {
            if (!rect.getProjectCode().equals(projectCode)) {
                continue;
            }
            ReferenceModel reference = new ReferenceModel();
            reference.setFlowName(rect.getModelName());
            reference.setFlowVer(rect.getVersion());
            referenceList.add(reference);
        }
        return referenceList;
    }
    
	@Override
	public void deleteByMutilVersion(Map<String, Object> map) {
		this.dao.deleteByMutilVersion(map);
	}
}